<?php
class pRoleAction extends pBaseAction{

    public function index(){
        $dao=new RoleModel();
        $count=$dao->count();
        if($count>0){
            import('@.Util.PageEx');
            $p=new PageEx($count,20);
            $this->assign('list',$dao->limit($p->firstRow.','.$p->listRows)->findAll());
            $this->assign('page',$p->show());
        }
        $this->display();
    }

    public function add(){
        $menuDao=new MenuModel();
        $this->assign('popelist',$menuDao->getPopedomTree());
        $this->display();
    }

    public function save(){
        $roleDao=new RoleModel();
        $roleRs=$roleDao->addRole();
        if($roleRs){
            $this->ok(
                L('add_success'),
                str_replace('roleName',$roleRs['name'],L('add_success_remark')),
                array(
                    array(L('gotoIndex'),'index'),
                    array(L('goonAdd'),'add')
                    )
            );
        }else{
            $this->fail(
                L('add_failure'),
                $roleDao->getError()
            );
        }
    }
}
